package com.example.demo.aop;


import com.example.demo.exception.BusinessException;
import lombok.extern.log4j.Log4j2;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;


@Aspect
@Component
@Log4j2
public class AopAspect {
    // 定义一个切点
    @Pointcut("@annotation(com.example.demo.annotation.LogAop)")
    public void serviceLayerExecution() {}
    @Around("serviceLayerExecution()")
    public Object Auth(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("-----环绕Aop生效了-------");
        return joinPoint.proceed();
    }


    // 前置通知
    @Before("serviceLayerExecution()")
    public void beforeServiceMethod(JoinPoint joinPoint) {
        log.info("-----前置通知Aop生效了-------");
    }

    // 后置通知
    @After("serviceLayerExecution()")
    public void afterServiceMethod() {
        log.info("-----后置通知Aop生效了-------");
    }

    // 返回后通知
    @AfterReturning(pointcut = "serviceLayerExecution()", returning = "result")
    public void afterReturningServiceMethod(Object result) {
        log.info("-----返回后通知Aop生效了-------");
    }

    // 异常后通知
    @AfterThrowing(pointcut = "serviceLayerExecution()", throwing = "ex")
    public void afterThrowingServiceMethod(Exception ex) {
        log.info("-----异常后通知Aop生效了-------");
    }



}
